//
//  YH_OtherFuntionViewController.m
//  YinHang
//
//  Created by idea on 14-9-17.
//  Copyright (c) 2014年 孙彦鹏. All rights reserved.
//

#import "YH_OtherFuntionViewController.h"

//下级页面
#import "FringdlyLinkViewController.h"//友情链接
#import "MessageBoardViewController.h"//留言板

@interface YH_OtherFuntionViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation YH_OtherFuntionViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //self.navigationController.navigationBarHidden = NO;
    self.navigationItem.title = @"其他功能";
    //返回
    UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 30)];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    negativeSpacer.width = - 10;
    if (ios7) {
        self.navigationItem.leftBarButtonItems = @[negativeSpacer,leftBarButtonItem];
    }else{
        self.navigationItem.leftBarButtonItems = @[leftBarButtonItem];
    }
       
    
    _strOfFuntion = @[@"友情链接",@"留言板",@"其他功能",@"其他功能2"];//功能名称
    [self setUI];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Custom Method



- (void)back {
    //self.navigationController.navigationBarHidden = YES;
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)setUI{
    UIScreen *screen = [UIScreen mainScreen];
    //
    UITableView *funtionTableView = [[UITableView alloc]initWithFrame:CGRectMake(30, 40, screen.bounds.size.width - 30 * 2, _strOfFuntion.count * 49)];
    //无分割线
    funtionTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    funtionTableView.backgroundColor = [UIColor whiteColor];
    funtionTableView.layer.cornerRadius=5.0;
    [self.view addSubview:funtionTableView];
    funtionTableView.delegate = self;
    funtionTableView.dataSource = self;
}

#pragma mark - UITableViewControllerDelegate


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _strOfFuntion.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"OtherFuntionViewCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"OtherFuntionViewCell" owner:nil options:nil][0];
    }
    NSUInteger row = [indexPath row];
    UILabel *lbl = (UILabel *)[cell.contentView viewWithTag:2];
    
    lbl.text = _strOfFuntion[row];
    //添加图片
    UIImageView *img_view = (UIImageView *)[cell.contentView viewWithTag:1];
    img_view.image = [UIImage imageNamed:@"item_64"];
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSUInteger row = [indexPath row];
    switch (row) {
        case 0:{
            FringdlyLinkViewController *flvc = [[FringdlyLinkViewController alloc]initWithNibName:@"FringdlyLinkViewController" bundle:nil];//进入友情链接
            [self.navigationController pushViewController:flvc animated:YES];
        }break;
        case 1:{
            MessageBoardViewController *mbvc = [[MessageBoardViewController alloc]initWithNibName:@"MessageBoardViewController" bundle:nil];//进入留言板
            [self.navigationController pushViewController:mbvc animated:YES];
        }break;
            
        default:
            break;
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


@end
